﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SGS.Cards;
using SGS.Utility;

namespace SGS.Standard.CardSelector
{
    /// <summary>
    /// “过河拆桥”、“顺手牵羊”、“反馈”、“归心”、“巧变”“寒冰剑”、“麒麟弓”的卡牌映射关系表
    /// 用于隐藏某些卡牌
    /// </summary>
    public class CardSelectorMapping
    {
        public CardSelectorMapping()
        {
        }

        public CardSelectorMapping(params Card[] cards)
        {
            MappingResult = cards.Select(p => new CardSelectorMappingItem(p, MappingPrivilege.Public, MappingType.SystemHeapCard)).ToList();
        }

        public CardSelectorMapping(Player player, MappingType type = MappingType.All)
        {
            MappingResult = FlagSwitchHelper<MappingType, CardSelectorMappingItem>.Switch(type,
                new Dictionary<MappingType, Func<List<CardSelectorMappingItem>>>()
                {
                    { 
                        MappingType.OwnCard, () =>
                        {
                            // 手牌位置随机化
                            return Common.RandomSort( player.GameInfo.OwnCards.ToList() ).Select( p => new CardSelectorMappingItem
                                ( p, MappingPrivilege.Hidden, MappingType.OwnCard ) ).ToList();
                        }
                    },
                    {
                        MappingType.Judge, () =>
                        {
                            return player.GameInfo.JudgeArea.Select(p=>new CardSelectorMappingItem(
                                p.UsedCards.First(), MappingPrivilege.Public, MappingType.Judge )).ToList();
                        }
                    },
                    {
                        MappingType.Horse, () =>
                        {
                            List<CardSelectorMappingItem> list = new List<CardSelectorMappingItem>();

                            if( player.GameInfo.AttackHorse != null )
                            {
                                list.Add( new CardSelectorMappingItem( player.GameInfo.AttackHorse, MappingPrivilege.Public, MappingType.Horse ) );
                            }

                            if (player.GameInfo.DefenseHorse != null)
                            {
                                list.Add( new CardSelectorMappingItem( player.GameInfo.DefenseHorse, MappingPrivilege.Public, MappingType.Horse ) );
                            }

                            return list;
                        }
                    },
                    {
                        MappingType.Armor, ()=>
                        {
                            List<CardSelectorMappingItem> list = new List<CardSelectorMappingItem>();

                            if (player.GameInfo.Armor != null)
                            {
                                list.Add( new CardSelectorMappingItem( player.GameInfo.Armor, MappingPrivilege.Public, MappingType.Armor ) );
                            }

                            return list;
                        }
                    },
                    {
                        MappingType.Weapon, ()=>
                        {
                            List<CardSelectorMappingItem> list = new List<CardSelectorMappingItem>();

                            if (player.GameInfo.Weapon != null)
                            {
                                list.Add( new CardSelectorMappingItem( player.GameInfo.Weapon, MappingPrivilege.Public, MappingType.Armor ) );
                            }

                            return list;
                        }
                    }
                });
        }

        public List<CardSelectorMappingItem> MappingResult
        {
            get;
            protected set;
        }
    }
}
